<template>
  <basic-container>
    <div class="card-border">
      <card-header :header-data="headerData"></card-header>
      <avue-crud :data="scheduleData"
                 :option="option"
                 :page="page"
                 :table-loading="tableLoading"
                 @size-change="sizeChange"
                 @current-change="currentChange"
                 @search-change="searchChange"
                 @search-reset="searchReset"
                 class="avuecrud">
        <template slot-scope="scope" slot="menu">
          <div class="menu-title" @click.stop="feedback(scope.row,scope.index)"
               v-if="!(scope.row.state == '0' || scope.row.state == '1' || scope.row.state == '2')">
            <i class="iconfont iconview icon-primary"></i>
            <p class="menu-title-text">查看反馈</p>
          </div>
        </template>
      </avue-crud>
    </div>
    <!--不采纳弹窗-->
    <el-dialog title="不采纳理由" :visible.sync="dialogVisibleDisagree">
      <el-input
        type="textarea"
        v-model="dialogRejectReason"
        rows="3"
      >
      </el-input>
      <div slot="footer" class="dialog-footer">
        <el-button @click="dialogVisibleDisagree = false">关 闭</el-button>
      </div>
    </el-dialog>
  </basic-container>
</template>
<script>
  import {toDoTargetOpinion} from "@/api/review";
  import {rejectOpinionPage} from "@/api/opinion";

  export default {
    name: "todoSubjectfinished",
    data() {
      return {
        headerData: {
          title: '课题征集'
        },
        page: {
          total: 0, // 总页数
          currentPage: 1, // 当前页数
          pageSize: 10 // 每页显示多少条
        },
        tableLoading: false,
        scheduleData: [],
        option: {
          page: true,
          addBtn: false,
          editBtn: false,
          addRowBtn: false,
          indexLabel: "序号",
          index: true,
          indexWidth:70,
          cellBtn: false,
          delBtn: false,
          columnBtn: false,
          refreshBtn: false,
          filterBtn: false,
          searchBtn: false,
          menuWidth: 120,
          keyId: "id",
          column: [
            {
              label: "课题征集主题",
              prop: "title",
              width: 450,
              cell: true,
              // formatter: function (row, value, label, column) {
              //   return '<a style="cursor: pointer;" onclick="viewDetail(\'' + row.targetId + '\')">' + value + '</a>';
              // },
            },  {
              label: "征集主题",
              prop: "titleLike",
              search: true,
              hide: true,
              cell: true,
            },{
              label: "发起部门",
              prop: "deptName",
              cell: true
            },
            {
              label: "截止日期",
              prop: "endDate",
              cell: true
            },
            {
              label: "状态",
              width: 80,
              prop: "state",
              cell: true,
              formatter: function (row, value, label, column) {
                switch (row.state) {
                  case '0':
                    return "<font color='red'>" + "催办" + "</font>";
                  case '1':
                    return "<font color='red'>" + "待反馈" + "</font>";
                  case '2':
                    return "<font color='#DCA450'>" + "补充" + "</font>";
                  case '3':
                    // return "<font color='#DCA450'>" + "不采纳" + "</font>";
                    return '<a style="cursor: pointer;color:#DCA450;" onclick="rejectReason(\'' + row.targetId + '\')">' + '不采纳' + '</a>';
                  case '4':
                    return "<font color='#7EBE50'>" + "已反馈" + "</font>";
                  case '5':
                    return "<font color='#7EBE50'>" + "已采纳" + "</font>";
                }
              }
            },
          ]
        },
        dialogVisibleDisagree: false,
        dialogRejectReason: '',
        titleLikeSearch: '',
      };
    },
    created() {
      this.getToDoList(this.page);
      window.viewDetail = this.viewDetail;
      window.rejectReason = this.rejectReason;
    },
    methods: {
      getToDoList(page, params) {
        this.tableLoading = true;
        toDoTargetOpinion(Object.assign({
          current: page.currentPage,
          size: page.pageSize,
          types: '4',
          states: '3,4,5',
          descs: 'create_time'
        }, params)).then(response => {
          this.scheduleData = response.data.data.records;
          this.page.total = response.data.data.total;
          this.tableLoading = false;
          this.$emit("getTotal", response.data.data.total)
        })
      },
      /**
       * 刷新回调
       */
      searchReset() {
        this.titleLikeSearch = '';
        let params = {
          titleLike:this.titleLikeSearch,
        };
        this.getToDoList(this.page,params);
      },
      //搜索回调
      searchChange (params) {
        this.page.currentPage = 1
        this.getToDoList(this.page, this.dealSearchParam(params));
      },
      // 处理搜索过滤
      dealSearchParam(params) {
        if (params.titleLike) {
          params.titleLike = params.titleLike;
        }
        this.titleLikeSearch = params.titleLike;
        return params;
      },
      currentChange(currentPage) {
        var page = this.page;
        page.currentPage = currentPage;
        let params = {
          titleLike:this.titleLikeSearch,
        };
        this.getToDoList(page,params);
      },
      sizeChange(pageSize) {
        var page = this.page;
        page.pageSize = pageSize;
        let params = {
          titleLike:this.titleLikeSearch,
        };
        this.getToDoList(page,params);
      },
      // 意见反馈
      feedback(row, index) {
        let src = `/subjectCollectionBack/add/${row.opinionId}`;
        this.$router.push({
          path: src,
          query: {
            type: row.type,
            targetId: row.targetId,
            toDoOrnot: '1',
            typeControlDetail: row.type,
            relateId: row.relateId,
          }
        })
      },
      //不采纳理由弹窗
      rejectReason(targetId) {
        rejectOpinionPage(Object.assign({
          targetId: targetId,
        })).then(response => {
          if (response.data.code == '0') {
            if (response.data.data.records != null && response.data.data.records.length != 0) {
              this.dialogRejectReason = response.data.data.records[0].opinion
            } else {
              this.dialogRejectReason = '无'
            }
            this.dialogVisibleDisagree = true;
          }
        })
      },
    }
  };
</script>

<style lang="scss" scoped>
  /deep/ .avue-crud__menu {
    min-height: 0px;
  }
</style>
